package com.abigdreamer.dicux;

import java.util.Map;

import com.abigdreamer.newspider.Article;
import com.abigdreamer.newspider.LoginFormInfo;
import com.abigdreamer.newspider.ThreadTaskManager;
import com.abigdreamer.util.FileUtil;

/**   
 * 
 * @author Darkness
 * @date 2013-6-2 下午05:23:05
 * @website http://www.abigdreamer.com 
 * @version V1.0   
 */
public class ArticleSpider extends ThreadTaskManager {
	LoginFormInfo loginFormInfo;
	public ArticleSpider(LoginFormInfo loginFormInfo) {
		this.loginFormInfo= loginFormInfo;
	}

	public void process(Map<String, Map<String, String>> map) {
		
		Map<String, Map<String, String>> articles = map;
		for (String fourmUrl : articles.keySet()) {
			for (String articleUrl : articles.get(fourmUrl).keySet()) {
				String value = articles.get(fourmUrl).get(articleUrl);

				Article article = new Article();
				article.setUrl(articleUrl);
				article.setTitle(value);
				addTask(article);
			}
			//System.out.println("版块[" + fourmUrl + "]下共抓取了" + articles.get(fourmUrl).size() + "篇文章");
		}

		for (int i = 0; i < 30; i++) {
			ArticleSpiderProcessor fourmSpider = new ArticleSpiderProcessor(this, this.loginFormInfo);
			addProcesser(fourmSpider);
		}

		startThread();
	}
}
